package com.swh.entity;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.swh.dao.base.BaseDao;

import java.util.ArrayList;
import java.util.List;

public class SysAreaListener<T> extends AnalysisEventListener<T> {

    private List<T> list = new ArrayList<>();

    private BaseDao baseDao;

    public SysAreaListener(BaseDao dao) {
        this.baseDao = dao;
    }

    @Override
    public void invoke(T data, AnalysisContext context) {
        list.add(data);
        if (list.size() >= 10) {
            baseDao.insert(data);
            list.clear();
        }
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext data) {
        if (list.size() >=0) {
            baseDao.insert(data);
            list.clear();
        }
    }

}